//
//  MantisGCDHandle.h
//  Runner
//
//  Created by iosdeveloper on 2020/8/30.
//  Copyright © 2020 The Chromium Authors. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN
/*
 GCD 一般用的就是切换主、子线程，开辟线程组，子线程里同步执行任务，控制并发
 */

//未写完------------



@class MantisGCDTool;


typedef MantisGCDTool *_Nullable(^MantisGCDHandlerBlock) (dispatch_block_t task);

@interface MantisGCDTool:NSObject
//是否异步
@property(nonatomic,assign)BOOL isAsync;
//是否分组
@property(nonatomic,assign)BOOL isGroup;
//存放线程的任务
@property(nonatomic,strong)NSMutableArray<dispatch_block_t> * blockContianer;
//分组里最大并行线程 default = 4;
@property(nonatomic,assign)int maxGroupThreadCount;


//执行任务
- (MantisGCDHandlerBlock)execute;
//主线程执行
- (MantisGCDTool *)executeInMain:(dispatch_block_t)task;
//子线程执行
- (MantisGCDTool *)executeInBackground:(dispatch_block_t)task;
//group
- (MantisGCDTool *)groupAsyncWithFinishedBlock:(dispatch_block_t)finish;
//!!!!!非常重要 实例类型链式操作 最后必须调用end！！！！
- (void)end:(dispatch_block_t)finish;

//主线程执行任务
+ (void)mainBlock:(dispatch_block_t)task;
//子线程执行任务
+ (void)backgroundBlock:(dispatch_block_t)task;

//并发执行 (如果并发为1，就是典型的生产者消费者模型)
+ (void)batchTaskWithAllCount:(int)taskCount
                maxConcurrent:(int)maxConcurrent
                         task:(NSArray <dispatch_block_t> *)task
                     finished:(dispatch_block_t)finished;
@end








@interface MantisGCDHandle : NSObject
/*-------*/
//异步
@property(nonatomic,strong)MantisGCDTool * async;
//同步
@property(nonatomic,strong)MantisGCDTool * sync;
//分组
@property(nonatomic,strong)MantisGCDTool * groupAsync;

+ (instancetype)defaultHandler;
@end

NS_ASSUME_NONNULL_END
